home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / snowfall / snowfall.c < prev    next >
C/C++ Source or Header  |  1980-01-04  |  6KB  |  229 lines

  1. /*    
  2.       This demo is written by Per Bratt.
  3.       
  4.       It can (should) be spread as long as it isn't changed and
  5.       my name/address is in it.
  6.       The sourche can NOT be separated from the program.
  7.       
  8.       The program is CARDWARE. If you like it (or if you don't)
  9.       send a card to
  10.       
  11.                   Per Bratt
  12.                   Döbelnsgatan 10 A
  13.                   752 37 Uppsala
  14.                   Sweden
  15.                   
  16.                   or email me at
  17.                   
  18.                   perbratt@canit.se
  19.                   
  20.       To the same addresses, you can send questions, suggestions,
  21.       statemenst, money (Im pooooor) and bug-reports.
  22.       If you'd like the source commented, I'll gladly do it.
  23.       Everything will be answered
  24.       
  25.       The source is ( except for Commodores headerfiles )
  26.       ready to be compiled. I used SAS C 5.10 and it's
  27.       assembler, but the file could probably be compiled with other
  28.       compilers too.
  29.  
  30.       Thanks to:
  31.       
  32.       Ander Bjerin ( the C-guru ), Per Helldahl ( suggestions, support )
  33.       Henrik Anniko ( support ), Stig Bratt ( support, suggestions ).
  34.       
  35.      The program:
  36.      This is just a demo of a snowfall. Tested on both A500 and A1200.
  37.  
  38.       Bugs:
  39.       None yet, but the randomfunction could be better.
  40.       Can YOU fix it?
  41.       
  42.                                                                   */
  43.  
  44. #include <graphics/view.h>
  45. #include <graphics/gfxbase.h>
  46. #include <graphics/gfxmacros.h>
  47. #include <time.h>
  48.  
  49. struct GfxBase *GfxBase;
  50.  
  51. extern void __asm wp(register __a0 UBYTE *, register __d0 WORD, register __d1 WORD);
  52. extern BYTE __asm sno(register __a0 UBYTE *, register __d0 WORD, register __d1 WORD);
  53.  
  54. struct View pview;
  55. struct View *oview;
  56. struct ViewPort pvport;
  57. struct RasInfo prasinfo;
  58. struct BitMap pbitmap[3];
  59. struct RastPort prp[3];
  60. struct cprlist *lofcprlist[2];
  61.  
  62. char *LeftMouse = (char *) 0xbfe001;
  63. char *ClockLow = (char *) 0xbfe801;
  64.  
  65. UBYTE *version = "$VER: Snowfall by Per Bratt. Version 1.12";
  66.  
  67. WORD colour_table[] = {0x000B, 0x0FFF};
  68.  
  69. void main();
  70.  
  71. void main()
  72. {
  73.    UWORD *pointer;
  74.    SHORT x,y=0,points[50][4];
  75.    UBYTE antal=0,number=0,hogst=255;
  76.    BOOL klar=FALSE;
  77.    BYTE ett=1,k;
  78.    UWORD klocka,slump[10];
  79.    
  80.    for(y=0;y<50;y++)
  81.    {
  82.       for(x=0;x<4;x++) points[y][x]=0;
  83.    }
  84.    
  85.    GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
  86.    if(GfxBase==NULL) exit(0);
  87.    
  88.    oview=GfxBase->ActiView;
  89.    
  90.    
  91.    InitView(&pview);
  92.    pview.ViewPort = &pvport;
  93.    InitVPort(&pvport);
  94.    pvport.DWidth = 320;
  95.    pvport.DHeight = 256;
  96.    pvport.RasInfo = &prasinfo;
  97.    pvport.Modes = NULL;
  98.    pvport.SpritePriorities = NULL;
  99.    pvport.DxOffset=0; 
  100.    pvport.DyOffset=0;
  101.    
  102.    pvport.ColorMap = (struct ColorMap *) GetColorMap( 2 );
  103.    
  104.    if(pvport.ColorMap==NULL) exit(0);
  105.    
  106.    pointer = (UWORD *) pvport.ColorMap->ColorTable;
  107.    
  108.    for(x=0;x<2;x++) *pointer++ = colour_table[x];
  109.    
  110.    for(y=0;y<3;y++)
  111.    {
  112.    
  113.    InitBitMap(&pbitmap[y],1,320,256);
  114.    
  115.    for(x=0;x<1;x++)
  116.    {
  117.       pbitmap[y].Planes[x]=(PLANEPTR) AllocRaster(320,256);
  118.       if(pbitmap[y].Planes[x]==NULL) exit(0);
  119.       BltClear(pbitmap[y].Planes[x],RASSIZE(320,256),0);
  120.    }
  121.    }
  122.    prasinfo.BitMap = &pbitmap[0];
  123.    prasinfo.RxOffset=0;
  124.    prasinfo.RyOffset=0;
  125.    prasinfo.Next = NULL;
  126.    
  127.    MakeVPort(&pview, &pvport);
  128.    MrgCop(&pview);
  129.    
  130.    lofcprlist[0] = pview.LOFCprList;
  131.    
  132.    pview.LOFCprList = NULL;
  133.    
  134.    prasinfo.BitMap = &pbitmap[1];
  135.    
  136.    MakeVPort(&pview, &pvport);
  137.    MrgCop(&pview);
  138.    
  139.    lofcprlist[1] = pview.LOFCprList;
  140.    
  141.    for(x=0; x<3; x++)
  142.    {
  143.    
  144.    InitRastPort(&prp[x]);
  145.    prp[x].BitMap=&pbitmap[x];
  146.    
  147.    
  148.    SetAPen(&prp[x],1);
  149.    }
  150.  
  151.    ett=1;
  152.  
  153. srand(time(NULL));
  154. for(x=0;x<10;x++)
  155. {
  156.    slump[x]=rand()%11;
  157. }
  158.  
  159.  
  160. while((*LeftMouse & 0x40)==0x40)
  161. {
  162.    BltClear(pbitmap[ett].Planes[0],RASSIZE(320,hogst),0);
  163.    BltBitMap(&pbitmap[2],0,hogst,&pbitmap[ett],0,hogst,320,255+1-hogst,0xC0,0xFF,NULL);
  164.    if(antal>0)
  165.    {
  166.       
  167.       for(y=0;y<(antal+1);y++)
  168.       {
  169.  
  170.       klar=FALSE;
  171.          if(points[y][3]==0) goto nope;
  172.        for(k=points[y][2];k>1;k--)
  173.        {
  174.          if(sno(pbitmap[2].Planes[0],points[y][0],points[y][1]+k)==0 && points[y][1]+k<256) break;
  175.        }
  176.        points[y][1]+=k;
  177.        if(points[y][1]>254) klar=TRUE;
  178.        else if(sno(pbitmap[2].Planes[0],points[y][0],points[y][1]+1)==1)
  179.        {
  180.          if(sno(pbitmap[2].Planes[0],points[y][0]-1,points[y][1]+1)==0 && points[y][0]>0) points[y][0]--;
  181.          else if(sno(pbitmap[2].Planes[0],points[y][0]+1,points[y][1]+1)==0 && points[y][0]<319) points[y][0]++;
  182.          else klar=TRUE;
  183.        } 
  184. nope:
  185.        if(klar==TRUE)
  186.        {
  187.           if(points[y][1]<hogst) hogst=points[y][1];
  188.           wp(pbitmap[2].Planes[0],points[y][0],points[y][1]);
  189.        points[y][3]=0; 
  190.        }
  191.  
  192.       }
  193.       WaitBlit();
  194.       for(y=0;y<antal+1;y++) if(points[y][3]==1) wp(pbitmap[ett].Planes[0],points[y][0],points[y][1]);
  195.    }
  196.    
  197.       klocka=*ClockLow;
  198.       if(klocka%5==3)
  199.       {
  200.          for(number=0;number<50;number++) if(points[number][3]==0) break;
  201.          if(number>antal) antal=number;
  202.          points[number][0]=((slump[(number*9)%10]*klocka)%321);
  203.          points[number][1]=0;
  204.          points[number][2]=(klocka%3)+1;
  205.          points[number][3]=1;
  206.       }
  207.       
  208.    
  209.    pview.LOFCprList = lofcprlist[ett];
  210.    LoadView(&pview);
  211.    ett=ett^1;
  212.    WaitTOF();
  213. }     
  214.    
  215.    LoadView(oview);
  216.    for(y=0;y<2;y++)
  217.    {
  218.    FreeCprList(lofcprlist[y]);
  219.    for(x=0;x<1;x++)
  220.    FreeRaster(pbitmap[y].Planes[x],320,256);
  221.    }
  222.    FreeVPortCopLists(&pvport);
  223.    FreeColorMap(pvport.ColorMap);
  224.    
  225.    CloseLibrary(GfxBase);
  226.    
  227. }
  228.  
  229.